package physics;

import java.awt.Point;

public class Coordinate {

	
	
	public double x;
	public double y;
	
	public Coordinate(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public double getX(){
		return x;
	}
	
	public double getY(){
		return y;
	}
	
	
	/**
	 * returns the angle from point 1 towards point 2
	 * @param 	coord1
	 * 				The first coordinate.
	 * @param	coord2
	 * 				The second coordinate.
	 * @return
	 * 			|the angle from point 1 towards point 2
	 */
	public static double getAngle(Coordinate coord1, Coordinate coord2){
		
		if (coord1.getX()==coord2.getX() && coord1.getY() == coord2.getY()){
		
			return 0;
		}
		else if (coord1.getY()==coord2.getY()){
			
			return (coord1.getX()<coord2.getX())?0:Math.PI;
			
		}
		
		else if (coord1.getX()==coord2.getX()){
			
			return -((coord1.getY()>coord2.getY())?-(Math.PI)/2:Math.PI/2);	
		}else{	
			
		return -Math.atan2(coord2.getY() - coord1.getY(), coord2.getX() - coord1.getX()) ;
		
		}
	}
	
	/**
	 * returns the distance between 2 points
	 * @param 	coord1
	 * 				The first coordinate.
	 * @param 	coord2
	 * 				The second coordinate.
	 * @return
	 * 			|the distance between the 2 points
	 */
	public static double getDistance(Coordinate coord1, Coordinate coord2){
		return Math.sqrt(Math.pow((coord1.getX()-coord2.getX()), 2) + Math.pow((coord1.getY()-coord2.getY()), 2));
	
	}
	
	/**
	 * This method adds a given vector to this coordinate.
	 * @param 	v
	 * 				The vector to add.
	 * @param 	coefficient
	 * 				The vector will be multiplied by this number before it is added.	
	 * @return	The coordinate resulting from adding the given vector to this coordinate.
	 */
	public Coordinate addVector(Vector v,double coefficient){
		Coordinate result = new Coordinate(this.x + (v.getxForce()  * coefficient), this.y + (v.getyForce() * coefficient));
		return result;
	}
	
	/**
	 * @return	This coordinate converted to a Point.
	 */
	public Point toPoint(){
		return new Point((int) this.x,(int) this.y);
	}
	
	public String toString(){
		return "(" + x + "," + y + ")";
	}
	public static void main(String args[]){
		int x1 = 1;
		int y1 = 1;
		int x2 = 2;
		int y2 = 2;
		
	}
	
	
}
